package cn.memedai.router.matcher;

import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;

import androidx.annotation.Nullable;

import java.util.Map;

import cn.memedai.router.RouteOptions;

/**
 * <p>write the description for the ${TYPE_NAME}
 *
 * @author gooljim
 * @version [版本号]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class MmdWebMatcher extends AbsExplicitMatcher {
    private static final String PRIVATE_PROTOC0L_PREFIX = "web";
    private static final String FLAG_PARAMETER_URL = "web_url";

    public MmdWebMatcher(int priority) {
        super(priority);
    }

    @Override
    public MatcherResult match(Context context, Uri uri, @Nullable Map<String, Class<? extends Activity>> activityTable, RouteOptions routeOptions) {
        MatcherResult matcherResult = MatcherResult.newInstance();
        if (activityTable==null||activityTable.size()==0||(!uri.toString().toLowerCase().startsWith("http://")
                && !uri.toString().toLowerCase().startsWith("https://"))) {
            return matcherResult;
        }
        Class <? extends Activity> router = activityTable.get(PRIVATE_PROTOC0L_PREFIX);
        if (router == null) {
            return matcherResult;
        }
        Bundle bundle = routeOptions.getBundle();
        if (bundle == null) {
            bundle = new Bundle();
            routeOptions.setBundle(bundle);
        }
        bundle.putString(FLAG_PARAMETER_URL, uri.toString());
        matcherResult.setMatch(true);
        matcherResult.setMatchClass(router);
        return matcherResult;
    }

}
